<?
if(isset($_COOKIE["EXPFOR"])){ 
	session_id($_COOKIE["EXPFOR"]); 
}
session_start();
/*$num = $_SESSION['imgcode'];
$w=(imagefontwidth(3)*strlen($num))+6;
$h=imagefontheight(3)+6;
$image = imagecreate($w,$h);

$textcolor = ImageColorAllocate($image, 255, 255, 255);
$background = ImageColorAllocate($image, 204, 204, 204);
imagefilledrectangle($image, 0, 0, $w, $h, $background);
imagestring($image, 3, 3, 3, (string)$num, $textcolor);
*/

// =====================
		$w=200; $h=70; $lines=60; $fsize=24;
		$img = imagecreatetruecolor($w,$h);
		$bgcolor = imagecolorallocate($img,255,255,255);

		imagefilledrectangle($img,0,0,$w,$h,$bgcolor);

		$color = imagecolorallocate($img,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
		$black = imagecolorallocate ($img, 0,0,0);

		$text = $_SESSION['imgcode'];

		$font = 'arial.ttf';

		for($i=0;$i<$lines;$i++)
		{
			$line1x = mt_rand(0,$w);
			$line2x = mt_rand(0,$w);
			$line1y = mt_rand(0,$h);
			$line2y = mt_rand(0,$h);

			$tempcolor = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(100,255));
			imageline($img,$line1x,$line1y,$line2x,$line2y,$tempcolor);
		}


		$font_abstracta = mt_rand($fsize/2,$fsize*1.5);
		$font_abstractb = mt_rand($fsize*1.4,$fsize*2);
		$font_size = mt_rand((int)($fsize*0.90),(int)($fsize*1.10));
		for($i = 0; $i<strlen($text);$i++)
		{
			imagecolordeallocate($img,$bgcolor);
			imagecolordeallocate($img,$color);

			$bgcolor= imagecolorallocate($img,255,255,255);
			$color = imagecolorallocate($img,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));

			$font_line = mt_rand(-7,7);
			$font_angle = mt_rand(-20,20);

			imagettftext($img,$font_size,$font_angle,$font_abstracta +2 + ($i*$fsize),$font_abstractb + 2 + $font_line,$bgcolor,$font,$text[$i]);
			imagettftext($img,$font_size,$font_angle,$font_abstracta + ($i*$fsize),$font_abstractb + 2 + $font_line,$color,$font,$text[$i]);
		}

		for ($i=0;$i<($lines/15);$i++)
		{
			$line1x = mt_rand(0,$w);
			$line2x = mt_rand(0,$w);
			$line1y = mt_rand(0,$h);
			$line2y = mt_rand(0,$h);

			$tempcolor = imagecolorallocate($img,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255));
			imageline($img,$line1x,$line1y,$line2x,$line2y,$tempcolor);
		}
// =======================
/*
header("Expires: Mon, 1 Jan 2000 01:23:45 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0");
*/

/*
$now = mktime (date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$expires = mktime (date("H"),date("i"),date("s") + 60 ,date("m"),date("d"),date("Y")); // 60 sec
$expires_gmt = gmdate('D, d M Y H:i:s', $expires).' GMT';
$last_modified_gmt  = gmdate('D, d M Y H:i:s', $now).' GMT';
*/
header('Content-type: image/png');
/*
header('Expires: '.$expires_gmt);
header('last-modified: '.$last_modified_gmt);
*/
imagePNG($img);
imagedestroy($img);
?>